package com.yuan.blog.job;

import com.yuan.blog.service.InvitataionScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @program: blog-core
 * @description:
 * @author: yuan_boss
 * @create: 2022-12-29 11:52
 **/
@Component
@Slf4j
public class InvitataionScoreJob {

    @Autowired
    private InvitataionScoreJob scoreJob;

    @Autowired
    private InvitataionScoreService scoreService;

    @Scheduled(cron = "0/59 * * * * *")
    public void scoreJob(){
        new Thread(()->{
            log.debug("计算帖子");
            // 1.先看下redis中是否有需要计算的帖子
            Long size = scoreService.getInvitationSize();
            if (size == 0) {
                log.info("本次任务没有帖子需要计算,任务结束");
                return;
            }

            // 2.计算帖子分数
            scoreService.refreshScore();
        }).start();
    }
}
